﻿using System.Collections.Generic;
using System.Windows;

namespace DynamicGeometry
{
    public class AngleMeasurement : MeasurementBase
    {
        public override void MoveToCore(Point newPosition)
        {
            Point newOffset = newPosition.Minus(Point(0));
            Offset = newOffset;
            base.MoveToCore(newPosition);
        }

        public override void UpdateVisual()
        {
            var p = Point(0).Plus(Offset);
            MoveToCore(p);
            base.UpdateVisual();
            Text = Math
                .OAngle(Point(1), Point(0), Point(2))
                .ToDegrees()
                .ToDegreeString();
        }

        [PropertyGridVisible]
        [PropertyGridName("Convert to opposite angle")]
        public void ConvertToOpposite()
        {
            IList<IFigure> dependencies = Dependencies as IList<IFigure>;
            if (dependencies != null)
            {
                var t = dependencies[1];
                dependencies[1] = dependencies[2];
                dependencies[2] = t;
            }
            this.RecalculateAndUpdateVisual();
        }
    }
}
